<script lang="ts" setup>
    import { House, ArrowRight, Refresh, Search, RefreshRight, CirclePlus} from "@element-plus/icons-vue"
    import { reactive } from 'vue'
    import axios from "../request/index";
    import { Dept } from "../model/index";
    import { onMounted } from "vue";
    import { useRouter } from "vue-router";
    import deptStore from '../store/DeptStore'

    const router = useRouter();

    let list1:Array<Dept> = [];
    let tableData = reactive({
            "list": list1
        });

    const getData = function (){
        axios({
            url: `/deptlist.do`,
            method: "GET"
        }).then((res)=>{
            //请求成功
            tableData.list = res.data;
        }).catch((err)=>{
            //请求失败·
            console.log(err);
        })
    }

    onMounted(() => {
      getData();
    });

    const formInline = reactive({
    user: '',
    region: '',
    date: '',
    })

    const onSubmit = () => {
    console.log('submit!')
    }

    const store = deptStore();

    let jump6_1 = function(){ router.push('/home/deptAdd'); };

    let jump6_2 = function( deptno : number){ 
      store.saveDeptno(deptno);
      router.push('/home/deptUpdate');
    };

</script>

<template>
  <el-container id="mainView">
    <el-header style="background-color: #272822; color: #E5E5E5; line-height: 60px; font-size: 27px;">部门信息管理</el-header>
    <el-footer style="height: 30px; line-height: 30px; background-color: #4E5246; border-bottom:1px solid #7A7A7A; border-top:1px solid #7A7A7A;">
      <el-breadcrumb :separator-icon="ArrowRight" style="line-height: 30px;">
        <el-breadcrumb-item :to="{ path: '/home/homepage' }"><el-icon><House /></el-icon>首页</el-breadcrumb-item>
        <el-breadcrumb-item>部门信息管理</el-breadcrumb-item>
      </el-breadcrumb>
    </el-footer>
    <el-main style="padding-bottom: 0%;">
        <div class="items">
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
                <el-form-item label="名称：">
                <el-input v-model="formInline.user" clearable />
                </el-form-item>
                <el-form-item label="状态：">
                <el-select
                    v-model="formInline.region"
                    placeholder="=请选择="
                    clearable
                >
                    <el-option label="活动" value="shanghai" />
                    <el-option label="撤销" value="beijing" />
                </el-select>
                </el-form-item>
                <el-form-item>
                <el-button type="primary" @click="onSubmit"><el-icon><Search /></el-icon>查询</el-button>
                <el-button type="primary" @click="onSubmit"><el-icon><RefreshRight /></el-icon>重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-divider style="margin: 16px;" />
        <div><el-button type="primary" @click="jump6_1"><el-icon><CirclePlus /></el-icon>新增</el-button></div>
        <div class="table">
            
            <el-table :data="tableData.list" border style="width: 96vw;">
                <el-table-column prop="deptno" label="部门编号" width="150px" />
                <el-table-column prop="dname" label="部门名称" width="100px"/>
                <el-table-column prop="locid" label="地区" width="100px"/>
                <el-table-column prop="" label="状态" width="100px"/>
                <el-table-column label="操作" >
                  <template #default="scope">
                    <el-button type="primary">
                      <el-icon><Refresh /></el-icon>查看
                    </el-button>
                    <el-button type="warning" @click="jump6_2(scope.row.deptno)">
                      <el-icon><Refresh /></el-icon>修改
                    </el-button>
                    <el-button type="danger">
                      <el-icon><Refresh /></el-icon>撤销
                    </el-button>
                    <el-button type="success">
                      <el-icon><Refresh /></el-icon>恢复
                    </el-button>
                  </template>
                </el-table-column>
            </el-table>
        </div>
    </el-main>
  </el-container>
</template>
  
<style scoped>
    #mainView {
        height: 100%;
        width: 100%;
    }

    .demo-form-inline .el-input {
    --el-input-width: 220px;
    }

    .demo-form-inline .el-select {
    --el-select-width: 220px;
    }

    .table {
      display: flex;
      justify-content: center;
    }

    .example-basic .el-date-editor {
      margin: 8px;
    }

</style>
  